package ihm;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

import metier.Film;
import metier.Horaire;
import metier.Salle;
import metier.Seance;
import metier.Tarif;
import dao.DaoProjetCinema;

public class FenetreMenu extends JFrame implements ActionListener
{

	private JPanel contentPane;
	private JMenuBar menuBar;
	private JMenu mnFichier;
	private JMenu mnDonnesMtiers;
	private JMenuItem mntmQuitter;
	private JMenu mnNouveau;
	private JMenuItem mntmSeance;
	private JMenuItem mntmFilm;
	private JMenuItem mntmTarif;
	private JMenuItem mntmSalle;
	private JMenu mnFilm;
	private JMenu mnSance;
	private JMenu mnTarif;
	private JMenu mnSalle;
	private JMenuItem mntmModifSupSeance;
	private JMenuItem mntmModifSupFilm;
	private JMenuItem mntmModifSupTarif;
	private JMenuItem mntmModifSupSalle;
	private JPanel panel;
	private JLabel lblCineImg;
	private JLabel lblBienvenue;
	
	private Vector<Film> lesFilms;
	private Vector<Tarif> lesTarifs;
	private Vector<Salle> lesSalles;
	private Vector<Seance> lesSeances;
	private Vector<Horaire> lesHoraires;

	/**
	 * Launch the applicationf.
	 */
	public static void main(String[] args)
	{
		EventQueue.invokeLater(new Runnable()
		{
			public void run()
			{
				try
				{
					FenetreMenu frame = new FenetreMenu();
					frame.setVisible(true);
				} catch (Exception e)
				{
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public FenetreMenu()
	{
		setTitle("Menu cin\u00E9ma");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 861, 522);
		
		this.menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		this.mnFichier = new JMenu("Fichier");
		this.menuBar.add(mnFichier);
		
		this.mnNouveau = new JMenu("Nouveau");
		this.mnFichier.add(mnNouveau);
		
		this.mntmSeance = new JMenuItem("Seance");
		this.mntmSeance.addActionListener(this);
		this.mnNouveau.add(mntmSeance);
		
		this.mntmFilm = new JMenuItem("Film");
		this.mntmFilm.addActionListener(this);
		this.mnNouveau.add(mntmFilm);
		
		this.mntmTarif = new JMenuItem("Tarif");
		this.mntmTarif.addActionListener(this);
		this.mnNouveau.add(mntmTarif);
		
		this.mntmSalle = new JMenuItem("Salle");
		this.mntmSalle.addActionListener(this);
		this.mnNouveau.add(mntmSalle);
		
		this.mntmQuitter = new JMenuItem("Quitter");
		this.mntmQuitter.addActionListener(this);
		this.mnFichier.add(mntmQuitter);
		
		this.mnDonnesMtiers = new JMenu("Donn\u00E9es m\u00E9tiers");
		this.menuBar.add(mnDonnesMtiers);
		
		this.mnSance = new JMenu("S\u00E9ance");
		this.mnDonnesMtiers.add(mnSance);
		
		this.mntmModifSupSeance = new JMenuItem("modifier/supprimer");
		this.mntmModifSupSeance.addActionListener(this);
		this.mnSance.add(mntmModifSupSeance);
		
		this.mnFilm = new JMenu("Film");
		this.mnDonnesMtiers.add(mnFilm);
		
		this.mntmModifSupFilm = new JMenuItem("modifier/supprimer");
		this.mntmModifSupFilm.addActionListener(this);
		this.mnFilm.add(mntmModifSupFilm);
		
		this.mnTarif = new JMenu("Tarif");
		this.mnDonnesMtiers.add(mnTarif);
		
		this.mntmModifSupTarif = new JMenuItem("modifier/supprimer");
		this.mntmModifSupTarif.addActionListener(this);
		this.mnTarif.add(mntmModifSupTarif);
		
		this.mnSalle = new JMenu("Salle");
		this.mnDonnesMtiers.add(mnSalle);
		
		this.mntmModifSupSalle = new JMenuItem("modifier/supprimer");
		this.mntmModifSupSalle.addActionListener(this);
		this.mnSalle.add(mntmModifSupSalle);
		contentPane = new JPanel();
		contentPane.setBackground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new BorderLayout(0, 0));
		
		panel = new JPanel();
		panel.setBackground(Color.WHITE);
		contentPane.add(panel, BorderLayout.CENTER);
		panel.setLayout(null);
		panel.setOpaque(true);
		
		this.lblCineImg = new JLabel("");
		this.lblCineImg.setIcon(new ImageIcon(FenetreMenu.class.getResource("/img/cine.jpg")));
		this.lblCineImg.setBounds(216, 113, 414, 219);
		panel.add(lblCineImg);
		
		JLabel lblBienvenue = new JLabel("Bienvenue");
		lblBienvenue.setFont(new Font("Verdana", Font.PLAIN, 24));
		lblBienvenue.setHorizontalAlignment(SwingConstants.CENTER);
		lblBienvenue.setBounds(328, 41, 151, 61);
		panel.add(lblBienvenue);
		
		this.lesTarifs = DaoProjetCinema.getLesTarif();
		this.lesFilms = DaoProjetCinema.getLesFilm();
		this.lesSalles = DaoProjetCinema.getLesSalle();
		this.lesSeances = DaoProjetCinema.getLesSeance();
		this.lesHoraires = DaoProjetCinema.getLesHoraire();		
	}
	
	public void actionPerformed(ActionEvent evt) 
	{
		contentPane.removeAll();
		JInternalFrame f = null;
		
		if (evt.getSource() == mntmQuitter )
		{
			 System.exit(0);
		}
		if (evt.getSource() == mntmFilm )
		{
			 f = new FenetreAjoutFilm(lesFilms);
		}
		if (evt.getSource() == mntmTarif )
		{
			 f = new FenetreAjoutTarif(lesTarifs);
		}
		if (evt.getSource() == mntmSeance )
		{
			 f = new FenetreAjoutSeance(lesSeances, lesTarifs, lesFilms, lesSalles, lesHoraires);
		}
		if (evt.getSource() == mntmSalle )
		{
			 f = new FenetreAjoutSalle(lesSalles);
		}
		if (evt.getSource() == mntmModifSupSalle )
		{
			 f = new FenetreModifSupSalle(lesSalles);
		}
		if (evt.getSource() == mntmModifSupFilm )
		{
			 f = new FenetreModifSupFilm(lesFilms);
		}
		if (evt.getSource() == mntmModifSupTarif ) 
		{
			 f = new FenetreModifSupTarif(lesTarifs);
		}
		if (evt.getSource() == mntmModifSupSeance )
		{
			 f = new FenetreModifSupSeance(lesTarifs, lesFilms);
		}
		contentPane.add(f);
	    f.setVisible(true);	
	}
}
